package com.tianyu.service.tcp.send;

import com.tianyu.common.ByteModel;
import com.tianyu.service.cache.DataCacheService;
import io.netty.channel.Channel;
import org.springframework.stereotype.Service;

/**********************************
 * @Author YSW
 * @Description
 * @Date 2024/8/1 - 14:55
 **********************************/

@Service
public interface TcpClientChannelSend {

    default void sendContent(Integer companyId, String boxSn, byte instructId, byte[] bytes) {
        final Channel channel = DataCacheService.tianyuTcpChannelMap.get(companyId);
        if (channel != null && channel.isOpen()) {
            final byte[] content = new byte[bytes.length + 16];
            System.arraycopy(boxSn.getBytes(), 0, content, 0, 15);
            System.arraycopy(new byte[]{instructId}, 0, content, 15, 1);
            System.arraycopy(bytes, 0, content, 16, bytes.length);
            channel.writeAndFlush(content);
        }
    }

}
